package leetcode.code0435;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int eraseOverlapIntervals(int[][] intervals) {
//		Arrays.sort(intervals, (a, b) -> a[1] == b[1] ? a[0] - b[0] : a[1] - b[1]);
		Arrays.sort(intervals, (a, b) ->  a[1] - b[1]);
		int ans = 0;
		int range = Integer.MIN_VALUE;// 0开始就错了
		for (int[] interval : intervals) {
			int l = interval[0], r = interval[1];
			if (l >= range) {
				range = r;
			} else {
				ans++;
			}
		}
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(7, this.eraseOverlapIntervals(HelpDebug.str2array1("[[-52,31],[-73,-26],[82,97],[-65,-11],[-62,-49],[95,99],[58,95],[-31,49],[66,98],[-63,2],[30,47],[-40,-26]]")));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
